<!--头部公共部分-->
{include file="common/header" /}
<script>
    var status_infos = '{$status_infos}'; //是否开班，1表示已开班
</script>
<div class="x-nav">
      <span class="layui-breadcrumb">
          <a>首页</a><a><cite>编辑学员</cite></a>
	  </span>
    <a class="layui-btn layui-btn-xs layui-btn-small" style="float:right;margin-top: 10px;"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon layui-icon-refresh"></i> </a>
</div>
<div style="padding:15px;">
    <form class="layui-form">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"><span class="x-red">*</span>学员姓名</label>
                <div class="layui-input-inline">
                    <script>
                        if(status_infos == 1){
                            document.write('<input type="text" readonly name="student_name" id="name" oninput="kehu()" value="{$student.student_name}"  placeholder="学员姓名" autocomplete="off" class="layui-input">');
                        }else{
                            document.write('<input type="text" name="student_name" id="name" oninput="kehu()" value="{$student.student_name}"  placeholder="学员姓名" autocomplete="off" class="layui-input">');
                        }
                    </script>
                    <!--
                    <input type="text" name="student_name" id="name" oninput="kehu()" value="{$student.student_name}"  placeholder="学员姓名" autocomplete="off" class="layui-input">
                    -->
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label"><span class="x-red">*</span>联系方式</label>
                <div class="layui-input-inline">
                    <input type="text" name="phone" value="{$student.phone}"  placeholder="联系方式" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label"><span class="x-red">*</span>客户姓名</label>
                <div class="layui-input-inline">
                    <input type="text" name="name" id="student_name" value="{$student.name}"  required  placeholder="客户姓名" readonly autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">就读年级</label>
                <div class="layui-input-inline">
                    <select name="grade"  lay-search="">
						<option value="{$student.grade}" {if $student.grade == 0}selected{/if}>请选年级</option>
                        {volist name="data[1]" id="v"}
                        <option value="{$v.id}" {if $student.grade == $v.id}selected{/if}>{$v['name']}</option>
                        {/volist}
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label"><span class="x-red">*</span>归属校区</label>
                <div class="layui-input-inline">
                    <input type="text"   value="{$campus_name}" autocomplete="off"   readonly class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">来源渠道</label>
                <div class="layui-input-inline">
                    <select name="channel" lay-search="">
                        <option value="">请选渠道</option>
                        {volist name="data[2]" id="v"}
                        <option value="{$v.id}" {if $student.channel == $v.id}selected{/if}>{$v['name']}</option>
                        {/volist}
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">学校班级</label>
                <div class="layui-input-inline">
                    <input type="text" value="{$student.school_class}" class="layui-input" name="school_class"  placeholder="学校班级">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">出生日期</label>
                <div class="layui-input-inline">
                    <input type="text" value="{$student.birth}" class="layui-input" name="birth" id="date" placeholder="yyyy-MM-dd">

                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">学员性别</label>
                <div class="layui-input-inline">
                    <select name="sex" lay-search="">
                        <option value="1" {if $student.sex == 1}selected{/if}>男</option>
                        <option value="2" {if $student.sex == 2}selected{/if}>女</option>
                    </select>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">课程顾问</label>
                <div class="layui-input-inline">
                    <select name="course_consultant_type">
                        <option value="1" selected>系统</option>
                        <option value="2">公海</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">监护对象</label>
                <div class="layui-input-inline">

                    <!--
                    <select name="guardian">
                        <option value=""></option>
                        {foreach name="data[30]" id="vo"}
                        <option value="{$vo.name}">{$vo.name}</option>
                        {/foreach}
                    </select>
                    -->

                    <script>
                        document.write('<select name="guardian">');
                        document.write('<option value=""></option>');
                        document.write('{foreach name="data[30]" id="vo"}');
                        var guardian = "{$student.guardian}";
                        if(guardian === "{$vo.name}"){
                            document.write('<option value="{$vo.name}" selected>{$vo.name}</option>');
                        }else{
                            document.write('<option value="{$vo.name}">{$vo.name}</option>');
                        }
                        document.write('{/foreach}');
                        document.write('</select>');
                    </script>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">电话号码</label>
                <div class="layui-input-inline">
                    <input type="text" name="guardian_phone" value="{$student.guardian_phone}" placeholder="电话" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">英文名</label>
                <div class="layui-input-inline">
                    <input type="text" name="english_name" value="{$student.english_name}"  placeholder="英文名" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">微信</label>
                <div class="layui-input-inline">
                    <input type="text" name="weixin" value="{$student.weixin}"  placeholder="微信" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">qq</label>
                <div class="layui-input-inline">
                    <input type="text"  name="qq" value="{$student.qq}" placeholder="qq" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item" hidden>
            <div class="layui-inline">
                <label class="layui-form-label">父亲姓名</label>
                <div class="layui-input-inline">
                    <input type="text" name="father_name" value="{$student.father_name}"  placeholder="父亲姓名" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">父亲电话</label>
                <div class="layui-input-inline">
                    <input type="text"  name="father_phone" value="{$student.father_phone}" placeholder="父亲电话" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item" hidden>
            <div class="layui-inline">
                <label class="layui-form-label">母亲姓名</label>
                <div class="layui-input-inline">
                    <input type="text" name="mother_name" value="{$student.mother_name}"  placeholder="母亲姓名" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">母亲电话</label>
                <div class="layui-input-inline">
                    <input type="text"  name="mother_phone" value="{$student.mother_phone}" placeholder="母亲电话" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-form-text" style="width: 650px;">
            <label class="layui-form-label">居住区域</label>
            <div class="layui-input-block">
                <textarea name="address" placeholder="请输居住区域" class="layui-textarea">{$student.address}</textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text" style="width: 650px;">
            <label class="layui-form-label">学员备注</label>
            <div class="layui-input-block">
                <textarea name="remark" placeholder="请输学员备注" class="layui-textarea">{$student.remark}</textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="hidden" name="id" value="{$student.id}">
                <input class="layui-btn" lay-submit lay-filter="form" value="保存" readonly>
                <script>
                    let type = parseInt('{$type}');
                    if(type != 101){
                        document.write('<a class="layui-btn layui-btn-primary" href="/admin/Student/information/id/{$student.id}">返回</a>');
                    }else{
                        document.write('<input class="layui-btn layui-btn-primary" lay-submit lay-filter="form_back" value="返回" readonly>');
                    }
                </script>

            </div>
        </div>
    </form>
</div>
<!--底部公共部分-->
{include file="common/footer" /}
<script>
    function kehu() {
        let name = document.getElementById("name").value;
        $('#student_name').val(name);
    }
    layui.use(['element', 'jquery','form','laydate','layer'], function () {
        var $ = layui.$,
            layer = layui.layer,
            form = layui.form,
            laydate = layui.laydate,
            element = layui.element,
            jquery = layui.jquery;

        //日期
        laydate.render({
            elem: '#date'
            ,trigger: 'click'
        });

        //监听提交
        form.on('submit(form)', function (data) {
            console.log(data);
            //发异步，把数据提交给php
            var field = data.field;
            var isLoad;
            $.ajax({
                url: '{:url("student/edit")}',
                method: "post",
                data: field,
                success: function (result) {
                    layer.msg(result.msg);
                    if (result.code === 0) {
                        setTimeout(function () {
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            parent.location.reload();
                        }, 2000);
                    }
                },
                complete: function () {
                    layer.close(isLoad)
                },
                error: function (error) {
                    console.log(error)
                }
            });
            return false;
        });

        //返回
        form.on('submit(form_back)', function (data) {
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
            parent.location.reload();
        });
    });
</script>